CC=g++
#wildcard, this finds all *.c file and make *.o files
objects = $(patsubst %.c,%.o,$(wildcard *.c))

# make sure root-config is defined
ROOTFLAGS := `root-config --cflags`
ROOTLIBS := -L`root-config --libdir` -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic

FFTWDIR := $(PWD)/fftw
FFTWIND := -I$(FFTWDIR)/include
FFTWLIB := -L$(FFTWDIR)/lib -lfftw3


all: sherpa_madgraph_comparison madgraph_multijet madgraph_multijet_cuttable \
	madgraph_example
#	example example_qcd example_corr sherpa_PDF_output sherpa_PDF_analysis


covariance.o : matrix_inverse.h

#rule for basic objects
%.o: %.c %.h
	$(CXX) -Wall -g -c $< -o $@

dataset.o: dataset.c dataset.h
	$(CXX) -Wall -g -c $< \
	$(FFTWIND) $(FFTWLIB) \
	-o $@

example: $(objects) example.C
	$(CXX) -O3 $(objects) tensor.h example.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o example.exe

example_qcd: $(objects) example_qcd.C
	$(CXX) -g $(objects) tensor.h example_qcd.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o example_qcd.exe

sherpa_PDF_output: $(objects) sherpa_PDF_output.C
	$(CXX) -g $(objects) tensor.h sherpa_PDF_output.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o sherpa_PDF_output.exe

sherpa_madgraph_comparison: $(objects) sherpa_madgraph_comparison.C
	$(CXX) -g $(objects) tensor.h sherpa_madgraph_comparison.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o sherpa_madgraph_comparison.exe

madgraph_example: $(objects) madgraph_example.C
	$(CXX) -g $(objects) tensor.h madgraph_example.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o madgraph_example.exe

bootstrap_example: $(objects) bootstrap_example.C
	$(CXX) -O3 $(objects) tensor.h bootstrap_example.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o bootstrap_example.exe

madgraph_multijet: $(objects) madgraph_multijet.C
	$(CXX) -g $(objects) tensor.h madgraph_multijet.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o madgraph_multijet.exe

madgraph_multijet_cuttable: $(objects) madgraph_multijet_cuttable.C
	$(CXX) -g $(objects) tensor.h madgraph_multijet_cuttable.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o madgraph_multijet_cuttable.exe

RPV_gluino: $(objects) RPV_gluino.C
	$(CXX) -g $(objects) tensor.h RPV_gluino.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o RPV_gluino.exe

example_sherpa: $(objects) example_sherpa.C
	$(CXX) -O3 $(objects) tensor.h example_sherpa.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o example_sherpa.exe

sherpa_PDF_analysis: $(objects) sherpa_PDF_analysis.C
	$(CXX) -g $(objects) tensor.h sherpa_PDF_analysis.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o sherpa_PDF_analysis.exe

example_corr: $(objects) example_corr.C
	$(CXX) -g $(objects) tensor.h example_corr.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o example_corr.exe

#example for reading in root file
example_root:  $(objects) example_root.C
	$(CXX) -O3 $(objects) tensor.h example_root.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o example_root.exe

#bandwdith study
example_bandwidth:  $(objects) example_bandwidth.C
	$(CXX) -O3 $(objects) tensor.h example_bandwidth.C \
	$(ROOTFLAGS) \
	$(ROOTLIBS) \
	$(FFTWIND) $(FFTWLIB) \
	-o example_bandwidth.exe
